//
//  CTAdjustImageView.m
//  ConstellationTalk_0.1
//
//  Created by riley on 15/5/15.
//  Copyright (c) 2015年 riley chu. All rights reserved.
//

#import "CTAdjustImageView.h"

#import "CTDebugManager.h"
#import "CTHeader.h"
#import "CTAppLanguage.h"
#import "CTDeviceFunction.h"
#import "UIViewAdditions.h"
#import "CTDeviceFunction.h"
#import "UIImage+Utility.h"
#import "CTFliterCollectionView.h"


@interface CTAdjustImageView ()<UIScrollViewDelegate,CTFliterCollectionViewDelegate>
{
    UIView * topView;
    UIView * filterBackGroundView;
    UIView * cutBackGroundView;
    UIView * cutView;
    UIView * filterView;
    
    UIScrollView * adjustScrollView;
    UIImageView * adjustView;
    
    
    UIView      * adjustOriginalView;
    UIImageView * adjustOriginalImageView;

    UIImage     * currentAdjustImage;
    
    
    UIButton    * cutBtn;
    UIButton    * filterBtn;
    
    UIImageView *firstCutImageView;
    UIImageView *secondCutImageView;
    UIButton    * firstCutDetailBtn;
    UIButton    * secondCutDetailBtn;
    
    UIScrollView *_filterScroll;
    
    UIImage *_originalImage;
    UIImage *_thumnailImage;
    NSArray *_filters;
    NSArray *_titleNames;
    
    float scrollView_x;
    float scrollView_y;
}

@end


@implementation CTAdjustImageView

@synthesize delegate;

- (void)dealloc
{
    delegate = nil;
    _originalImage = nil;
    _thumnailImage = nil;
    _filters = nil;
    _titleNames = nil;
    [_filterScroll removeFromSuperview];
    _filterScroll = nil;
    [adjustView removeFromSuperview];
    adjustView = nil;
    [topView removeFromSuperview];
    topView = nil;
    [cutView removeFromSuperview];
    cutView = nil;
    [filterView removeFromSuperview];
    filterView = nil;
    [cutBackGroundView removeFromSuperview];
    cutBackGroundView = nil;
    [filterBackGroundView removeFromSuperview];
    filterBackGroundView = nil;
    [adjustScrollView removeFromSuperview];
    adjustScrollView = nil;
    [adjustOriginalView removeFromSuperview];
    adjustOriginalView = nil;
    [adjustOriginalImageView removeFromSuperview];
    adjustOriginalImageView = nil;
    
 
    [CTDebugManager showDebugLogInfo:@"dealloc : CTAdjustImageView Is Removed!!!"];
}

- (instancetype)initWithType:(CTAdjustImageViewType)adjustType
{
    self = [super init];
    if (self) {
        self.frame = CGRectMake(0, 0, CT_HEADER_SCREEN_WIDTH, CT_HEADER_SCREEN_HEIGHT);
        self.backgroundColor = CT_HEADER_WHITE_COLOR;
        
        [self creatSubviews];
        if (adjustType== CTAdjustImageViewTypeDefault)
        {
            [self creatSelectionView];
            
        }
        else
        {
            UIView * shadowView  = [[UIView alloc]initWithFrame:CGRectMake(0, CT_HEADER_SCREEN_WIDTH+64, CT_HEADER_SCREEN_WIDTH, CT_HEADER_SCREEN_WIDTH)];
            shadowView.backgroundColor = CT_HEADER_WHITE_COLOR;
            shadowView.alpha = 0.8;
            [self addSubview:shadowView];
        }
    }
    return self;
}

#pragma mark - creat subViews -
-(void)creatSubviews
{
    
    UILabel * topBottomLine = [[UILabel alloc]initWithFrame:CGRectMake(0, topView.frame.size.height-0.5, CT_HEADER_SCREEN_WIDTH, 0.5)];
    topBottomLine.backgroundColor = CT_HEADER_DEEPLINE_COLOR;
    [topView addSubview:topBottomLine];

    
    
    adjustScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 64, CT_HEADER_SCREEN_WIDTH, CT_HEADER_SCREEN_WIDTH)];
    adjustScrollView.backgroundColor = [UIColor colorWithRed:240/255.0 green:240/255.0 blue:240/255.0 alpha:1.0f];
    adjustScrollView.delegate = self;
    adjustScrollView.showsHorizontalScrollIndicator = NO;
    adjustScrollView.showsVerticalScrollIndicator = NO;
    adjustScrollView.layer.masksToBounds = NO;
    [self addSubview:adjustScrollView];

    
    adjustView = [[UIImageView alloc] initWithFrame:CGRectZero];
    adjustView.backgroundColor = [UIColor colorWithRed:240/255.0 green:240/255.0 blue:240/255.0 alpha:1.0f];
    [adjustScrollView addSubview:adjustView];
    
    
    adjustOriginalView = [[UIView alloc] initWithFrame:CGRectMake(0, 64, CT_HEADER_SCREEN_WIDTH, CT_HEADER_SCREEN_WIDTH)];
    adjustOriginalView.backgroundColor = [UIColor colorWithRed:240/255.0 green:240/255.0 blue:240/255.0 alpha:1.0f];
    adjustOriginalView.hidden = YES;
    [self addSubview:adjustOriginalView];
    
    adjustOriginalImageView = [[UIImageView alloc] initWithFrame:CGRectZero];
    [adjustOriginalView addSubview:adjustOriginalImageView];
    
    topView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, CT_HEADER_SCREEN_WIDTH, 64)];
    topView.backgroundColor = CT_HEADER_WHITE_COLOR;
    [self addSubview:topView];
    
    UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 20, CT_HEADER_SCREEN_WIDTH, 44)];
    titleLabel.text = [CTAppLanguage localizedStringForKey:@"adjustView_topView_title" withValue:nil withTable:@"Language"];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.textColor = CT_HEADER_GREEN_COLOR;
    titleLabel.font = [UIFont fontWithName:nil size:19];
    [topView addSubview:titleLabel];
    
    UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    backButton.frame = CGRectMake(0, 20, 44, 44);
    [backButton addTarget:self action:@selector(backBtn:) forControlEvents:UIControlEventTouchUpInside];
    [backButton setImage:[UIImage imageNamed:CT_HEADER_BACK_IMAGE] forState:UIControlStateNormal];
    [backButton setImage:[UIImage imageNamed:CT_HEADER_BACK_IMAGE_CLICK] forState:UIControlStateHighlighted];
    //    [backButton setTitleColor:CT_HEADER_WHITE_COLOR forState:UIControlStateNormal];
    //    [backButton setTitle:[CTAppLanguage localizedStringForKey:@"adjustView_topView_back" withValue:nil withTable:@"Language"] forState:UIControlStateNormal];
    [topView addSubview:backButton];
    
    UIButton * confirmBtn =[UIButton buttonWithType:UIButtonTypeCustom];
    confirmBtn.frame = CGRectMake(CT_HEADER_SCREEN_WIDTH-60, 20, 55, 44);
    [confirmBtn addTarget:self action:@selector(nextStepBtn:) forControlEvents:UIControlEventTouchUpInside];
    [confirmBtn setTitleColor:CT_HEADER_GREEN_COLOR forState:UIControlStateNormal];
    confirmBtn.titleLabel.font = [UIFont systemFontOfSize:15.0];
    [confirmBtn setTitle:[CTAppLanguage localizedStringForKey:@"adjustView_topView_next" withValue:nil withTable:@"Language"] forState:UIControlStateNormal];
    [topView addSubview:confirmBtn];
    
 
}

-(void)creatSelectionView
{
    
    UIView * backGroundView = [[UIView alloc] initWithFrame:CGRectMake(0, CT_HEADER_SCREEN_HEIGHT-64, CT_HEADER_SCREEN_WIDTH, 64)];
    backGroundView.backgroundColor = [UIColor clearColor];
    [self addSubview:backGroundView];
    
    
    UIView * selectionView = [[UIView alloc] initWithFrame:backGroundView.bounds];
    selectionView.backgroundColor = CT_HEADER_WHITE_COLOR;
    [backGroundView addSubview: selectionView];
    
    UILabel * topBottomLine = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, CT_HEADER_SCREEN_WIDTH, 0.5)];
    topBottomLine.backgroundColor = CT_HEADER_DEEPLINE_COLOR;
    [backGroundView addSubview:topBottomLine];

    
    cutBtn =[UIButton buttonWithType:UIButtonTypeCustom];
    cutBtn.frame = CGRectMake(0,0,CT_HEADER_SCREEN_WIDTH/2.0,64);
    [cutBtn addTarget:self action:@selector(cutBtn:) forControlEvents:UIControlEventTouchUpInside];
    [cutBtn setImage:[UIImage imageNamed:@"tiaozhengdaxiao_click"] forState:UIControlStateNormal];
    [backGroundView addSubview:cutBtn];
    
    filterBtn =[UIButton buttonWithType:UIButtonTypeCustom];
    filterBtn.frame = CGRectMake(CT_HEADER_SCREEN_WIDTH/2.0,0,CT_HEADER_SCREEN_WIDTH/2.0,64);
    [filterBtn addTarget:self action:@selector(filterBtn:) forControlEvents:UIControlEventTouchUpInside];
    filterBtn.selected = NO;
    [filterBtn setImage:[UIImage imageNamed:@"lvjing"] forState:UIControlStateNormal];
    [backGroundView addSubview:filterBtn];
    
    
    [self creatCutViewDetails];
    [self creatFilterViewDetails];
    
    selectionView.alpha = 0.8;
}

-(void)creatCutViewDetails
{
    
    DeviceTypeAdaptation deviceType = [CTDeviceFunction deviceTypeForResolutionAdaptation];
    if (deviceType == iPhone4_4s)
    {
        cutBackGroundView = [[UIView alloc] initWithFrame:CGRectMake(0, CT_HEADER_SCREEN_HEIGHT-64-60, CT_HEADER_SCREEN_WIDTH, 60)];
    }
    else if(deviceType == iPhone5_5s_5c)
    {
        cutBackGroundView = [[UIView alloc] initWithFrame:CGRectMake(0, CT_HEADER_SCREEN_HEIGHT-64-120, CT_HEADER_SCREEN_WIDTH, 120)];
    }
    else
    {
        cutBackGroundView = [[UIView alloc] initWithFrame:CGRectMake(0, CT_HEADER_SCREEN_HEIGHT-64-128, CT_HEADER_SCREEN_WIDTH, 128)];
    }
//    cutBackGroundView = [[UIView alloc] initWithFrame:CGRectMake(0, CT_HEADER_SCREEN_HEIGHT-64-128, CT_HEADER_SCREEN_WIDTH, 128)];
    cutBackGroundView.backgroundColor = [UIColor clearColor];
    [self addSubview:cutBackGroundView];
    
    cutView = [[UIView alloc] initWithFrame:cutBackGroundView.bounds];
    cutView.backgroundColor = CT_HEADER_WHITE_COLOR;
    cutView.alpha = 0.8;
    [cutBackGroundView addSubview:cutView];
    
    
    firstCutDetailBtn =[UIButton buttonWithType:UIButtonTypeCustom];
    [firstCutDetailBtn setTitle:@"1:1" forState:UIControlStateNormal];
    [firstCutDetailBtn setTitleColor:CT_HEADER_GREEN_COLOR forState:UIControlStateNormal];
    firstCutDetailBtn.frame = CGRectMake(0,0,CT_HEADER_SCREEN_WIDTH/2.0,128);
    [firstCutDetailBtn addTarget:self action:@selector(cutDetailBtn:) forControlEvents:UIControlEventTouchUpInside];
    [cutBackGroundView addSubview:firstCutDetailBtn];
    firstCutImageView = [[UIImageView alloc]initWithFrame:CGRectMake((firstCutDetailBtn.frame.size.width-90)/2, 19, 90, 90)];
    firstCutImageView.image = [UIImage imageNamed:@"lvjing_xuanzhongkuang"];
    [firstCutDetailBtn addSubview:firstCutImageView];
    
    secondCutDetailBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    secondCutDetailBtn.frame = CGRectMake(CT_HEADER_SCREEN_WIDTH/2, 0, CT_HEADER_SCREEN_WIDTH/2, 128);
    [secondCutDetailBtn addTarget:self action:@selector(secondCutDetailBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [secondCutDetailBtn setTitle:@"4:3" forState:UIControlStateNormal];
    [secondCutDetailBtn setTitleColor:CT_HEADER_DEEPLINE_COLOR forState:UIControlStateNormal];
    [cutBackGroundView addSubview:secondCutDetailBtn];
    
    secondCutImageView = [[UIImageView alloc]initWithFrame:CGRectMake((secondCutDetailBtn.frame.size.width-90)/2, 19, 90, 90)];
    secondCutImageView.image = [UIImage imageNamed:@"sibisan"];
    [secondCutDetailBtn addSubview:secondCutImageView];
    
    

    
}

-(void)creatFilterViewDetails
{
    filterBackGroundView = [[UIView alloc] initWithFrame:CGRectMake(0, CT_HEADER_SCREEN_HEIGHT-64-128, CT_HEADER_SCREEN_WIDTH, 128)];
    filterBackGroundView.hidden = YES;
    filterBackGroundView.backgroundColor = [UIColor clearColor];
    [self addSubview:filterBackGroundView];
    
    filterView = [[UIView alloc] initWithFrame:filterBackGroundView.bounds];
    filterView.backgroundColor = CT_HEADER_WHITE_COLOR;
    [filterBackGroundView addSubview:filterView];
    filterView.alpha = 0.8;
    
}


//虑镜

#pragma mark - action & delegate -

-(void)backBtn:(id)sender
{
    if ([self.delegate respondsToSelector:@selector(backAction:)]) {
        [self.delegate backAction:self];
    }
}



-(void)nextStepBtn:(id)sender
{
    UIImage * shotScreenImage;
    if (adjustScrollView.hidden == NO) {
        //1:1
        
//        float pixelsTimes;
//
//        DeviceTypeAdaptation  adaptation = [CTDeviceFunction deviceTypeForResolutionAdaptation];
//        switch (adaptation) {
//            case iPhone4_4s:
//                if (currentAdjustImage.size.width < currentAdjustImage.size.height) {
//                    pixelsTimes = 2.05;
//                }else{
//                    pixelsTimes = 3;
//                }
//                break;
//            case iPhone5_5s_5c:
//                if (currentAdjustImage.size.width < currentAdjustImage.size.height) {
//                    pixelsTimes = 2.40;
//                }else{
//                    pixelsTimes = 2.45;
//                }
//                break;
//            case iPhone6:
//                if (currentAdjustImage.size.width < currentAdjustImage.size.height) {
//                    pixelsTimes = 2.25;
//                }else{
//                    pixelsTimes = 2.15;
//                }
//                break;
//            case iPhone6_Plus:
//                if (currentAdjustImage.size.width < currentAdjustImage.size.height) {
//                    pixelsTimes = 2.05;
//                }else{
//                    pixelsTimes = 2.1;
//                }
//                break;
//            default:
//                break;
//        }
        
//        float pixelsTimes;
//        
//        int height = [UIScreen mainScreen].bounds.size.height;
//        int times = [UIScreen mainScreen].scale;
//        
//        if (times * height == 960 || times * height == 480)
//        {
//            if (currentAdjustImage.size.width < currentAdjustImage.size.height) {
//                pixelsTimes = 2.05;
//            }else{
//                pixelsTimes = 3;
//            }
//        }
//        else if (times * height == 1136)
//        {
//            if (currentAdjustImage.size.width < currentAdjustImage.size.height) {
//                pixelsTimes = 2.4;
//            }else{
//                pixelsTimes = 2.45;
//            }
//        }
//        else if (times * height == 1334)
//        {
//            if (currentAdjustImage.size.width < currentAdjustImage.size.height) {
//                pixelsTimes = 2.25;
//            }else{
//                pixelsTimes = 2.15;
//            }
//        }
//        else if (times * height == 2001 )
//        {
//            if (currentAdjustImage.size.width < currentAdjustImage.size.height) {
//                pixelsTimes = 2.05;
//            }else{
//                pixelsTimes = 2.1;
//            }
//        }
//        else if( times * height == 2208)
//        {
//            if (currentAdjustImage.size.width < currentAdjustImage.size.height) {
//                pixelsTimes = 3.1;
//            }else{
//                pixelsTimes = 2.56;
//            }
//        }
        topView.hidden = YES;
        adjustScrollView.frame = CGRectMake(adjustScrollView.frame.origin.x, 0, CT_HEADER_SCREEN_WIDTH, adjustScrollView.frame.size.height);
        shotScreenImage = [CTDeviceFunction imageFromView:self atFrame:CGRectMake(0, 0, CT_HEADER_SCREEN_WIDTH, adjustScrollView.frame.size.height)];
    }else{
        //4:3
       shotScreenImage = [CTDeviceFunction imageFromView:adjustOriginalView atFrame:adjustOriginalView.bounds];
    }

    
    if ([self.delegate respondsToSelector:@selector(nextStepAction:withImg:)]) {
        [self.delegate nextStepAction:self withImg:shotScreenImage];
    }
}
#pragma mark -UIScrollViewDelegate -
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
   
    if (scrollView.contentOffset.x > 0)
    {
        scrollView_x = scrollView.contentOffset.x;

    }
    
    scrollView_y = scrollView.contentOffset.y;
    
}

-(void)cutBtn:(UIButton *)sender
{
    
    [filterBtn setImage:[UIImage imageNamed:@"lvjing"] forState:UIControlStateNormal];
  
    [cutBtn setImage:[UIImage imageNamed:@"tiaozhengdaxiao_click"] forState:UIControlStateNormal];
    if (cutView == nil)
    {
        [self creatCutViewDetails];
    }
    else
    {
        cutBackGroundView.hidden = NO;
        filterBackGroundView.hidden = YES;
    }
}

-(void)filterBtn:(UIButton *)sender
{
    [filterBtn setImage:[UIImage imageNamed:@"lvjing_click"] forState:UIControlStateNormal];
    
    [cutBtn setImage:[UIImage imageNamed:@"tiaozhengdaxiao"] forState:UIControlStateNormal];
   
    if (filterView == nil)
    {
        [self creatFilterViewDetails];
    }
    else
    {
        filterBackGroundView.hidden = NO;
        cutBackGroundView.hidden = YES;
    }
}

-(void)cutDetailBtn:(UIButton *) sender
{
    [self cutForOneToOne:sender];
    [firstCutDetailBtn setTitleColor:CT_HEADER_GREEN_COLOR forState:UIControlStateNormal];
    firstCutImageView.image = [UIImage imageNamed:@"lvjing_xuanzhongkuang"];
    [secondCutDetailBtn setTitleColor:CT_HEADER_DEEPLINE_COLOR forState:UIControlStateNormal];
    secondCutImageView.image = [UIImage imageNamed:@"sibisan"];
        
}
- (void)secondCutDetailBtnAction:(UIButton *) sender
{
    [self cutForFourToThree:sender];
    [secondCutDetailBtn setTitleColor:CT_HEADER_GREEN_COLOR forState:UIControlStateNormal];
    secondCutImageView.image = [UIImage imageNamed:@"sibisan_click"];
    [firstCutDetailBtn setTitleColor:CT_HEADER_DEEPLINE_COLOR forState:UIControlStateNormal];
    firstCutImageView.image = [UIImage imageNamed:@"yibiyi"];
}

-(void)filterDetailBtn:(id)sender
{
    
}


-(void)cutForOneToOne:(id)sender
{
    adjustScrollView.hidden = NO;
    adjustOriginalView.hidden = YES;
}
-(void)cutForFourToThree:(id)sender
{
    adjustScrollView.hidden = YES;
    adjustOriginalView.hidden = NO;
}


#pragma mark - setter -

-(void)setAdjustImage:(UIImage *)adjustImage
{
    
    if (adjustImage == nil) {
        return;
    }
    
    float width = adjustImage.size.width;
    float height = adjustImage.size.height;
    
    currentAdjustImage = adjustImage;
    
    //1：1比例
    if (width < height) {
        adjustScrollView.contentSize = CGSizeMake(adjustScrollView.frame.size.width+1, (adjustScrollView.frame.size.width*height/width));
        adjustView.frame = CGRectMake(0,-20,adjustScrollView.contentSize.width, adjustScrollView.contentSize.height+20);
    }else{
        adjustScrollView.contentSize = CGSizeMake(adjustScrollView.frame.size.height*width/height,adjustScrollView.frame.size.height);
        adjustView.frame = CGRectMake(0,-20,adjustScrollView.contentSize.width, adjustScrollView.contentSize.height+20);
    }
    
    
    adjustView.image = adjustImage;
    
    
    //4：3比例
    if (width<height) {
        adjustOriginalImageView.frame = CGRectMake((CT_HEADER_SCREEN_WIDTH-adjustOriginalView.frame.size.height*width/height)/2.0,0, adjustOriginalView.frame.size.height*width/height, adjustOriginalView.frame.size.height);
    }else{
        adjustOriginalImageView.frame = CGRectMake(0,(adjustOriginalView.frame.size.height-CT_HEADER_SCREEN_WIDTH * height/width)/2.0, CT_HEADER_SCREEN_WIDTH, CT_HEADER_SCREEN_WIDTH * height/width);
    }
    adjustOriginalImageView.image = adjustImage;
    
    [self setup];
    

}
//虑镜
- (void)setup
{
//    [self setFilters];
//    
//    _originalImage = currentAdjustImage;
//    float   image_x = currentAdjustImage.size.width;
//    float   image_y = currentAdjustImage.size.height;
//    _thumnailImage = [_originalImage aspectFill:CGSizeMake(image_x/1.5, image_y/1.5)];
//    _filterScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, filterView.frame.size.width, filterView.frame.size.height)];
//    _filterScroll.showsHorizontalScrollIndicator = NO;
//    [filterView addSubview:_filterScroll];
//    
//    [self setFilterMenu];
    CTFliterCollectionView *filterCollectionView = [[CTFliterCollectionView alloc]initWithFrame:CGRectMake(0, 0, filterView.frame.size.width, filterView.frame.size.height)];
    filterCollectionView.delegate = self;
    filterCollectionView.filterImg  = currentAdjustImage;
//    filterCollectionView.backgroundColor = [UIColor redColor];
    [filterView addSubview:filterCollectionView];
    
    
}

- (void) filterCollectionViewDidSelected:(CTFliterCollectionView *)view withImage:(UIImage *)image
{
    adjustOriginalImageView.image = image;
    adjustView.image = image;

}
#pragma mark-

//- (void)setFilters
//{
//    _filters = @[
//                 @{@"name":@"Original",                 @"title":@"None",       @"version":@(0.0)},
//                 @{@"name":@"CISRGBToneCurveToLinear",  @"title":@"Linear",     @"version":@(7.0)},
//                 @{@"name":@"CIVignetteEffect",         @"title":@"Vignette",   @"version":@(7.0)},
//                 @{@"name":@"CIPhotoEffectInstant",     @"title":@"Instant",    @"version":@(7.0)},
//                 @{@"name":@"CIPhotoEffectProcess",     @"title":@"Process",    @"version":@(7.0)},
//                 @{@"name":@"CIPhotoEffectTransfer",    @"title":@"Transfer",   @"version":@(7.0)},
//                 @{@"name":@"CISepiaTone",              @"title":@"Sepia",      @"version":@(5.0)},
//                 @{@"name":@"CIPhotoEffectChrome",      @"title":@"Chrome",     @"version":@(7.0)},
//                 @{@"name":@"CIPhotoEffectFade",        @"title":@"Fade",       @"version":@(7.0)},
//                 @{@"name":@"CILinearToSRGBToneCurve",  @"title":@"Curve",      @"version":@(7.0)},
//                 @{@"name":@"CIPhotoEffectTonal",       @"title":@"Tonal",      @"version":@(7.0)},
//                 @{@"name":@"CIPhotoEffectNoir",        @"title":@"Noir",       @"version":@(7.0)},
//                 @{@"name":@"CIPhotoEffectMono",        @"title":@"Mono",       @"version":@(7.0)},
//                 @{@"name":@"CIColorInvert",            @"title":@"Invert",     @"version":@(6.0)},
//                 ];
////    _titleNames = @[@"原图",@"蓝调",@"哥特",@"迷情",@"珊瑚",@"暮秋",@"复古",@"苦艾",@"云端",@"梦幻",@"流年",@"黑白",@"天使之吻",@"曝光"];
////}
//
//- (void)setFilterMenu
//{
//    CGFloat W = 60;
//    CGFloat x = 10;
//    int i =1000;
//    for(NSDictionary *filter in _filters){
//
//        
//            UIImageView *iconView = [[UIImageView alloc] initWithFrame:CGRectMake(x, 40, W, W)];
//            iconView.clipsToBounds = YES;
//            iconView.tag = i;
//            iconView.userInteractionEnabled = YES;
//            iconView.contentMode = UIViewContentModeScaleAspectFill;
//            [_filterScroll addSubview:iconView];
//            
//            UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(x, W+40, W, 29)];
//            label.text = [_titleNames objectAtIndex:i-1000];
//            label.font = [UIFont systemFontOfSize:13];
//            label.textAlignment = NSTextAlignmentCenter;
//            [_filterScroll addSubview:label];
//            
//            UITapGestureRecognizer *gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tappedFilterPanel:)];
//            [iconView addGestureRecognizer:gesture];
//            
//            x += W+25;
//            i +=1;
//            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
//                
//            UIImage *iconImage = [self filteredImage:_thumnailImage withFilterName:[filter objectForKey:@"name"]];
//                
//                dispatch_async(dispatch_get_main_queue(), ^{
//                    iconView.image = iconImage;
////                    adjustView.image = iconImage;
//                });
//            });
//    }
//    _filterScroll.contentSize = CGSizeMake(MAX(x-15, _filterScroll.frame.size.width+1), 0);
//}
//
//- (UIImage*)filteredImage:(UIImage*)image withFilterName:(NSString*)filterName
//{
//    if([filterName isEqualToString:@"Original"]){
//        return _originalImage;
//    }
//    
//    CIImage *ciImage = [[CIImage alloc] initWithImage:image];
//    CIFilter *filter = [CIFilter filterWithName:filterName keysAndValues:kCIInputImageKey, ciImage, nil];
//    
////        [filter setDefaults];
//    
//    if([filterName isEqualToString:@"CIVignetteEffect"]){
//        // parameters for CIVignetteEffect
//                CGFloat R = MIN(image.size.width, image.size.height)/2;
//                CIVector *vct = [[CIVector alloc] initWithX:image.size.width/2 Y:image.size.height/2];
//                [filter setValue:vct forKey:@"inputCenter"];
//                [filter setValue:[NSNumber numberWithFloat:0.9] forKey:@"inputIntensity"];
//                [filter setValue:[NSNumber numberWithFloat:R] forKey:@"inputRadius"];
//    }
//    
//    CIContext *context = [CIContext contextWithOptions:nil];
//    CIImage *outputImage = [filter outputImage];
//    CGImageRef cgImage = [context createCGImage:outputImage fromRect:[outputImage extent]];
//    
//    UIImage *result = [UIImage imageWithCGImage:cgImage];
//    
//    CGImageRelease(cgImage);
//    
//    return result;
//}
//
//- (void)tappedFilterPanel:(UITapGestureRecognizer*)sender
//{
//    int i =(int)sender.view.tag;
//    NSDictionary *dic;
//    NSString * str;
//    dic = [_filters objectAtIndex:(i-1000)];
//    str = [dic objectForKey:@"name"];
//    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
//        
//    UIImage *image = [self filteredImage:_thumnailImage withFilterName:
//                          str];
//        
//        dispatch_async(dispatch_get_main_queue(), ^{
//            adjustOriginalImageView.image = image;
//            adjustView.image = image;
//        });
//        
//    });
//}


@end


